package cn.itacst.upload;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//将数据打印到控制台
public class UploadServlet1 extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");

		//怎么从request对象中获取上传的数据？
		ServletInputStream in = request.getInputStream();
		int temp = 0;
		while((temp = in.read()) != -1){
			//将数据打印到控制台
			System.out.write(temp);
		}

		response.setContentType("text/html;charset=utf-8");
		String content = "你好,我来自UploadServlet1";

		String prefix="<font size='4' color='red'>";
		String postfix="</font>";
		String responseContent=prefix+content+postfix;
		response.getWriter().print(responseContent);

		System.out.println("----------------------------UploadServlet1 结束------------------------------");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
